package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author stone
 * @date 2022/06/22 11:11
 */
@RestController
public class NoteController {


    //该注解获得value属性指定的占位符的值，并且把该值赋给对应的形参
    @RequestMapping("note/{id}")
    public BaseRespVo note(@PathVariable("id") Integer id) {

        return BaseRespVo.ok();
    }

    public NoteController() {
        System.out.println("controller init");
    }



    // localhost:8080/login?username=songge&password=niupi
    @RequestMapping("login")
    public BaseRespVo login(@RequestParam("username") String username,
                            @RequestParam("password") String password) {
        return BaseRespVo.ok();
    }

    @RequestMapping("header")
    public BaseRespVo header(@RequestHeader("Accept") String[] accept,
                             @RequestHeader("Host") String host) {
        return BaseRespVo.ok(accept);
    }

    @RequestMapping("cookievalue")
    public BaseRespVo cookieValue(@CookieValue("songge") String value) {
        return BaseRespVo.ok(value);
    }

    @RequestMapping("session/put/{value}")
    public BaseRespVo sessionPut(HttpSession session,@PathVariable("value")String value) {
        session.setAttribute("username", value);
        return BaseRespVo.ok();
    }

    @RequestMapping("session/get")
    public BaseRespVo sessionGet(@SessionAttribute("username")String username) {
        return BaseRespVo.ok(username);
    }
}
